package org.autumn.thread;

import java.util.concurrent.TimeUnit;

public class ThreadState {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
        }, "t1");

        Thread t2 = new Thread(() -> {
            while (true){}
        }, "t2");
        t2.start();
        Thread t3 = new Thread(() -> {
        }, "t3");
        t3.start();
        Thread t4 = new Thread(() -> {
            try {
                synchronized (ThreadState.class){
                    TimeUnit.HOURS.sleep(1);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t4");

        t4.start();
        Thread t5 = new Thread(() -> {
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t5");

        t5.start();
        Thread t6 = new Thread(() -> {
            synchronized (ThreadState.class){
            }
        }, "t6");

        t6.start();

        TimeUnit.SECONDS.sleep(1);

        /**
         * t1 state ->NEW
         * t2 state ->RUNNABLE
         * t3 state ->TERMINATED
         * t4 state ->TIMED_WAITING
         * t5 state ->WAITING
         * t6 state ->BLOCKED
         */
        System.out.println("t1 state ->" + t1.getState());
        System.out.println("t2 state ->" + t2.getState());
        System.out.println("t3 state ->" + t3.getState());
        System.out.println("t4 state ->" + t4.getState());
        System.out.println("t5 state ->" + t5.getState());
        System.out.println("t6 state ->" + t6.getState());
    }
}
